﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sovacode.RubiksCube.Common.Base;
using Sovacode.RubiksCube.Common.Exceptions;
using Sovacode.RubiksCube.Common.Model;

namespace Sovacode.RubiksCube.Common.Tests.Model
{
    [TestClass]
    public class CommonDataObjectTests
    {
        [TestMethod]
        public void CreateDataObject()
        {
            var data = new DataObject();

            Assert.IsNotNull(data);

            Assert.IsFalse(data.Modified);
            Assert.IsFalse(data.Readonly);
            Assert.IsTrue(data.IsValid);
        }

        [TestMethod]
        public void UpdateProperties()
        {
            var data = new DataObject();

            Assert.IsTrue(string.IsNullOrWhiteSpace(data.Name));
            Assert.IsTrue(string.IsNullOrWhiteSpace(data.DisplayName));

            data.Name = "Sample";

            Assert.IsFalse(string.IsNullOrWhiteSpace(data.Name));
            Assert.IsFalse(string.IsNullOrWhiteSpace(data.DisplayName));

            Assert.IsTrue(string.CompareOrdinal(data.Name, data.DisplayName) == 0);
            Assert.IsTrue(data.Modified);
        }

        [TestMethod]
        [ExpectedException(typeof (ReadOnlyObjectException))]
        public void UpdateReadonly()
        {
            var data = new DataObject();

            Assert.IsFalse(data.Readonly);

            data.Readonly = true;

            Assert.IsTrue(data.Readonly);

            data.Name = "Sample";
        }

        [TestMethod]
        public void Remove()
        {
            var data = new DataObject();

            Assert.IsFalse(data.Removed);

            data.Remove();

            Assert.IsTrue(data.Removed);
        }

        [TestMethod]
        [ExpectedException(typeof (NotImplementedException))]
        public void Reload()
        {
            var data = new DataObject();

            data.Reload();
        }

        [TestMethod]
        public void MustExposes()
        {
            var data = new DataObject();

            Assert.IsInstanceOfType(data, typeof (INotifyValidatedObject));
            Assert.IsInstanceOfType(data, typeof (IDataObject));
            Assert.IsInstanceOfType(data, typeof (INotifyPropertyChanged));
            Assert.IsInstanceOfType(data, typeof (INotifyValidatedObject));
            Assert.IsInstanceOfType(data, typeof (NotifyValidatedObject));

        }
    }
}
